import skStorage from '@/utils/storage'
import { reactive, toRefs } from 'vue'

type GloballType = {
	prefixClass: string
}
/**
 * 全局工具类 可以帮助跨页面调用
 * @param opt
 * @returns
 */
export function useGlobal(opt?: Partial<GloballType>) {
	const state = reactive({})
	function setStorage<T>(key: string, data: T) {
		skStorage.set(key, data)
	}
	function getStorage<T>(key: string): T {
		return skStorage.get(key) as T
	}
	function removeStorage(key: string) {
		skStorage.remove(key)
	}
	return {
		getStorage,
		removeStorage,
		setStorage,
		...toRefs(state),
	}
}
